package cn.cs.controller;
import cn.cs.common.Dto;
import cn.cs.common.DtoUtil;
import cn.cs.common.RedisUtils;
import cn.cs.service.AgentManageService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/agentManage")
public class AgentManageController {
    @Resource
    private  AgentManageService agentManageService;
    /****
     * 获取A级经销商下面所有的B级经销商
     * @param
     * @param
     * @return
     */
    @RequestMapping("/getAgentLevelB")
    @ResponseBody
    public Dto getAgentLevelB(HttpServletRequest request, HttpServletResponse response){
        Dto dto=null;
        try {
            response.setHeader("Access-Control-Allow-Origin", "*");
            dto=agentManageService.getAgentLevelB(request);
        }catch (Exception e){
            e.printStackTrace();
            return DtoUtil.returnFail("查询失败","002");
        }
        return dto;
    }


    /****
     * 查看B级经销商店铺详细信息
     * @param
     * @param
     * @return
     */
    @RequestMapping("/getAgentShopInfo")
    @ResponseBody
    public Dto getAgentShopInfo(HttpServletRequest request, HttpServletResponse response){
        Dto dto=null;
        try {
            response.setHeader("Access-Control-Allow-Origin", "*");
            dto=agentManageService.getAgentShopInfo(request);
        }catch (Exception e){
            e.printStackTrace();
            return DtoUtil.returnFail("查询失败","002");
        }
        return dto;
    }

    /****
     * 升级权限
     * @param
     * @param
     * @return
     */
    @RequestMapping("/setPower")
    @ResponseBody
    public Dto setPower(HttpServletRequest request, HttpServletResponse response){
        Dto dto=null;
        try {
            response.setHeader("Access-Control-Allow-Origin", "*");
            dto=agentManageService.setPower(request);
        }catch (Exception e){
            e.printStackTrace();
            return DtoUtil.returnFail("修改失败","002");
        }
        return dto;
    }
    /****
     * 获取A级经销商下面所有的B级经销商数量
     * @param
     * @param
     * @return
     */
    @RequestMapping("/getAgentLevelBCount")
    @ResponseBody
    public Dto getAgentLevelBCount(HttpServletRequest request, HttpServletResponse response){
        Dto dto=null;
        try {
            response.setHeader("Access-Control-Allow-Origin", "*");
            dto=agentManageService.getAgentLevelBCount(request);
        }catch (Exception e){
            e.printStackTrace();
            return DtoUtil.returnFail("查询失败","002");
        }
        return dto;
    }

    /****
     * A级经销商邀请B级有抽成经销商
     * @param
     * @param
     * @return
     */
    @RequestMapping("/invitationAgentLevelB")
    @ResponseBody
    public Dto invitationAgentLevelB(HttpServletRequest request, HttpServletResponse response){
        Dto dto=null;
        try {
            response.setHeader("Access-Control-Allow-Origin", "*");
            dto=agentManageService.invitationAgentLevelB(request);
        }catch (Exception e){
            e.printStackTrace();
            return DtoUtil.returnFail("查询失败","002");
        }
        return dto;
    }

    /****
     * B级经销商邀请B级无抽成经销商
     * @param
     * @param
     * @return
     */
    @RequestMapping("/invitationAgentLevelB2")
    @ResponseBody
    public Dto invitationAgentLevelB2(HttpServletRequest request, HttpServletResponse response){
        Dto dto=null;
        try {
            response.setHeader("Access-Control-Allow-Origin", "*");
            dto=agentManageService.invitationAgentLevelB2(request);
        }catch (Exception e){
            e.printStackTrace();
            return DtoUtil.returnFail("查询失败","002");
        }
        return dto;
    }

    /****
     * B级经销商邀请页面数据
     * @param
     * @param
     * @return
     */
    @RequestMapping("/dataAgentLeveB")
    @ResponseBody
    public Dto dataAgentLeveB(HttpServletRequest request, HttpServletResponse response){
        Dto dto=null;
        try {
            response.setHeader("Access-Control-Allow-Origin", "*");
            dto=agentManageService.dataAgentLeveB(request);
        }catch (Exception e){
            e.printStackTrace();
            return DtoUtil.returnFail("查询失败","002");
        }
        return dto;
    }

    /****
     * 获取B级经销商发展的维修工和商铺
     * @param
     * @param
     * @return
     */
    @RequestMapping("/devRepAndShop")
    @ResponseBody
    public Dto devRepAndShop(HttpServletRequest request, HttpServletResponse response){
        Dto dto=null;
        try {
            response.setHeader("Access-Control-Allow-Origin", "*");
            dto=agentManageService.devRepAndShop(request);
        }catch (Exception e){
            e.printStackTrace();
            return DtoUtil.returnFail("查询失败","002");
        }
        return dto;
    }


    /****
     * 获取发展商铺信息
     * @param
     * @param
     * @return
     */
    @RequestMapping("/getNearShopInfo")
    @ResponseBody
    public Dto getNearShopInfo(HttpServletRequest request, HttpServletResponse response){
        Dto dto=null;
        try {
            response.setHeader("Access-Control-Allow-Origin", "*");
            dto=agentManageService.getNearShopInfo(request);
        }catch (Exception e){
            e.printStackTrace();
            return DtoUtil.returnFail("查询失败","002");
        }
        return dto;
    }

    /****
     * 添加实体店
     * @param
     * @param
     * @return
     */
    @RequestMapping("/addNearShop")
    @ResponseBody
    public Dto addNearShop(HttpServletRequest request, HttpServletResponse response){
        Dto dto=null;
        try {
            response.setHeader("Access-Control-Allow-Origin", "*");
            dto=agentManageService.addNearShop(request);
        }catch (Exception e){
            e.printStackTrace();
            return DtoUtil.returnFail("查询失败","002");
        }
        return dto;
    }

    /****
     * 设置默认体现方式
     * @param
     * @param
     * @return
     */
    @RequestMapping("/setDefaultTX")
    @ResponseBody
    public Dto setDefaultTX(HttpServletRequest request, HttpServletResponse response){
        Dto dto=null;
        try {
            response.setHeader("Access-Control-Allow-Origin", "*");
            dto=agentManageService.setDefaultTX(request);
        }catch (Exception e){
            e.printStackTrace();
            return DtoUtil.returnFail("查询失败","002");
        }
        return dto;
    }

    /****
     * 设置默认体现方式
     * @param
     * @param
     * @return
     */
    @RequestMapping("/getMainPros")
    @ResponseBody
    public Dto getMainPros(HttpServletRequest request, HttpServletResponse response){
        Dto dto=null;
        try {
            response.setHeader("Access-Control-Allow-Origin", "*");
            dto=agentManageService.getMainPros(request);
        }catch (Exception e){
            e.printStackTrace();
            return DtoUtil.returnFail("查询失败","002");
        }
        return dto;
    }

}
